package cn.aj.basic.controller;

import cn.aj.basic.service.IVerifyCodeImageService;
import cn.aj.basic.tdo.EmailCodeDto;
import cn.aj.basic.tdo.SmsCodeDto;
import cn.aj.basic.tdo.WxLoginSmsCodeDto;
import cn.aj.basic.utils.AjaxResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifyCodeImage")
public class VerifyCodeImageController {

    @Autowired
    private IVerifyCodeImageService verifyCodeImageService;


    /**
    * @Title: verifyCodeImage
    * @Description: TODO
    * @Author: Mr.GT
    * @Version: 1.0
    * @Date:  2022/11/23 0023 16:03
    * @Parameters: [imageCodeKey]
    * @Return void
     * 手机图形验证吗
    */
    @GetMapping("/{imageCodeKey}")
    public AjaxResultUtil loadImage(@PathVariable("imageCodeKey") String imageCodeKey) {
        String base64Img = verifyCodeImageService.loadImg(imageCodeKey);
        return AjaxResultUtil.getAjaxResult().setResultObj(base64Img);
    }

    /**
    * @Title: loadImage
    * @Description: TODO
    * @Author: Mr.GT
    * @Version: 1.0
    * @Date:  2022/11/24 0024 23:46
    * @Parameters: [imageCodeKey]
    * @Return cn.aj.basic.utils.AjaxResultUtil
     * 邮件图形验证码
    */
    @GetMapping("/email/{emailCodeKey}")
    public AjaxResultUtil loadEmail(@PathVariable("emailCodeKey") String emailCodeKey) {
        String base64Email = verifyCodeImageService.loadEmail(emailCodeKey);
        return AjaxResultUtil.getAjaxResult().setResultObj(base64Email);
    }

    /**
    * @Title: smsCode
    * @Description: TODO
    * @Author: Mr.GT
    * @Version: 1.0
    * @Date:  2022/11/24 0024 15:21
    * @Parameters: []
    * @Return cn.aj.basic.utils.AjaxResultUtil
     * 手机短信验证 wxLoginCode
    */
    @PostMapping("/smsCode")
    public AjaxResultUtil getSmsCode(@RequestBody SmsCodeDto smsCodeDto) {
        verifyCodeImageService.getSmsCode(smsCodeDto);
        return AjaxResultUtil.getAjaxResult().success();
    }

    /**
    * @Title: getSmsCode
    * @Description: TODO
    * @Author: Mr.GT
    * @Version: 1.0
    * @Date:  2022/11/27 0027 22:59
    * @Parameters: [smsCodeDto]
    * @Return cn.aj.basic.utils.AjaxResultUtil
     * 微信登录手机绑定,发短信
    */
    @PostMapping("/wxLoginCode")
    public AjaxResultUtil getWxLoginCode(@RequestBody WxLoginSmsCodeDto wxLoginSmsCodeDto) {
        verifyCodeImageService.getWxLoginSmsCode(wxLoginSmsCodeDto);
        return AjaxResultUtil.getAjaxResult().success();
    }

    /**
    * @Title: getEmailCode
    * @Description: TODO
    * @Author: Mr.GT
    * @Version: 1.0
    * @Date:  2022/11/25 0025 0:15
    * @Parameters: [emailCodeDto]
    * @Return cn.aj.basic.utils.AjaxResultUtil
     * 邮件验证
    */
    @PostMapping("/emailCode")
    public AjaxResultUtil getEmailCode(@RequestBody EmailCodeDto emailCodeDto) {
        verifyCodeImageService.getEmailCode(emailCodeDto);
        return AjaxResultUtil.getAjaxResult().success();
    }
}
